# -*- coding: utf-8 -*-
"""
Created on Tue Nov 21 14:17:24 2017

@author: xuanlei
"""

from pro_data import JrttCaptcha
import numpy as np

def JrttCaptchaGenerator(batch_size, path):
    # to determine dimensions
    cap = JrttCaptcha()
    img, text = cap.get_captcha()
    shape = np.asarray(img).shape
    vocab = Vocab()
    while (1):
        X = np.empty((batch_size, shape[0], shape[1], shape[2]))
        Y = np.empty((batch_size, len(text) * vocab_size))
        for j in range(batch_size):
            img, text = cap.get_captcha()
            #img.save(path + text + ".jpg")
            X[j] = np.array(img) / 255
            Y[j] = vocab.text_to_one_hot(text)
        yield X, Y
        


#datagen = ImageDataGenerator(
#        featurewise_center=False,  # set input mean to 0 over the dataset
#        samplewise_center=False,  # set each sample mean to 0
#        featurewise_std_normalization=False,  # divide inputs by std of the dataset
#        samplewise_std_normalization=False,  # divide each input by its std
#        zca_whitening=False,  # apply ZCA whitening
#        rotation_range=0,  # randomly rotate images in the range (degrees, 0 to 180)
#        width_shift_range=0.1,  # randomly shift images horizontally (fraction of total width)
#        height_shift_range=0.1,  # randomly shift images vertically (fraction of total height)
#        horizontal_flip=True,  # randomly flip images
#vertical_flip=False) # randomly flip images
## Compute quantities required for featurewise normalization
## (std, mean, and principal components if ZCA whitening is applied).
#    datagen.fit(x_train)
## Fit the model on the batches generated by datagen.flow().
#model.fit_generator(datagen.flow(x_train, y_train,
#                                     batch_size=batch_size),
#                        steps_per_epoch=x_train.shape[0] // batch_size,
#                        epochs=epochs,
#validation_data=(x_test, y_test))